/*********************************************************************
	Rhapsody	: 7.6
	Login		: Pawel
	Component	: DefaultComponent
	Configuration 	: DefaultConfig
	Model Element	: Doors
//!	Generated Date	: Sun, 20, Nov 2011 
	File Path	: DefaultComponent/DefaultConfig/CargoLiftSystem/Doors.java
*********************************************************************/

package CargoLiftSystem;

//## class Doors 
import Hardware.IDoors;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.*;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.states.*;

//----------------------------------------------------------------------------
// CargoLiftSystem/Doors.java                                                                  
//----------------------------------------------------------------------------

//## package CargoLiftSystem 


//## class Doors 
public class Doors implements RiJStateConcept, IDoors {
    
    public Reactive reactive;		//## ignore 
    
    protected Lift itsLift;		//## link itsLift 
    
    //#[ ignore 
    public static final int RiJNonState=0;
    public static final int readyToClose=1;
    public static final int open=2;
    public static final int closed=3;
    //#]
    protected int rootState_subState;		//## ignore 
    
    protected int rootState_active;		//## ignore 
    
    public static final int Doors_Timeout_readyToClose_id = 1;		//## ignore 
    
    
    //## statechart_method 
    public RiJThread getThread() {
        return reactive.getThread();
    }
    
    //## statechart_method 
    public void schedTimeout(long delay, long tmID, RiJStateReactive reactive) {
        getThread().schedTimeout(delay, tmID, reactive);
    }
    
    //## statechart_method 
    public void unschedTimeout(long tmID, RiJStateReactive reactive) {
        getThread().unschedTimeout(tmID, reactive);
    }
    
    //## statechart_method 
    public boolean isIn(int state) {
        return reactive.isIn(state);
    }
    
    //## statechart_method 
    public boolean isCompleted(int state) {
        return reactive.isCompleted(state);
    }
    
    //## statechart_method 
    public RiJEventConsumer getEventConsumer() {
        return (RiJEventConsumer)reactive;
    }
    
    //## statechart_method 
    public void gen(RiJEvent event) {
        reactive._gen(event);
    }
    
    //## statechart_method 
    public void queueEvent(RiJEvent event) {
        reactive.queueEvent(event);
    }
    
    //## statechart_method 
    public int takeEvent(RiJEvent event) {
        return reactive.takeEvent(event);
    }
    
    // Constructors
    
    //## auto_generated 
    public  Doors(RiJThread p_thread) {
        reactive = new Reactive(p_thread);
    }
    
    //## auto_generated 
    public Lift getItsLift() {
        return itsLift;
    }
    
    //## auto_generated 
    public void __setItsLift(Lift p_Lift) {
        itsLift = p_Lift;
    }
    
    //## auto_generated 
    public void _setItsLift(Lift p_Lift) {
        if(itsLift != null)
            {
                itsLift.__setItsDoors(null);
            }
        __setItsLift(p_Lift);
    }
    
    //## auto_generated 
    public void setItsLift(Lift p_Lift) {
        if(p_Lift != null)
            {
                p_Lift._setItsDoors(this);
            }
        _setItsLift(p_Lift);
    }
    
    //## auto_generated 
    public void _clearItsLift() {
        itsLift = null;
    }
    
    //## auto_generated 
    public boolean startBehavior() {
        boolean done = false;
        done = reactive.startBehavior();
        return done;
    }
    
    //## ignore 
    public class Reactive extends RiJStateReactive {
        
        // Default constructor 
        public Reactive() {
            this(RiJMainThread.instance());
        }
        
        
        // Constructors
        
        public  Reactive(RiJThread p_thread) {
            super(p_thread);
            initStatechart();
        }
        
        //## statechart_method 
        public boolean isIn(int state) {
            if(rootState_subState == state)
                {
                    return true;
                }
            return false;
        }
        
        //## statechart_method 
        public boolean isCompleted(int state) {
            return true;
        }
        
        //## statechart_method 
        public void rootState_entDef() {
            {
                rootState_enter();
                rootStateEntDef();
            }
        }
        
        //## statechart_method 
        public int rootState_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            switch (rootState_active) {
                case closed:
                {
                    res = closed_takeEvent(id);
                }
                break;
                case open:
                {
                    res = open_takeEvent(id);
                }
                break;
                case readyToClose:
                {
                    res = readyToClose_takeEvent(id);
                }
                break;
                default:
                    break;
            }
            return res;
        }
        
        //## auto_generated 
        protected void initStatechart() {
            rootState_subState = RiJNonState;
            rootState_active = RiJNonState;
        }
        
        //## statechart_method 
        public void closedExit() {
        }
        
        //## statechart_method 
        public void readyToClose_exit() {
            readyToCloseExit();
        }
        
        //## statechart_method 
        public int closedTakeOpenDoors() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            closed_exit();
            open_entDef();
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public int open_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.NULL_EVENT_ID))
                {
                    res = openTakeNull();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void closed_entDef() {
            closed_enter();
        }
        
        //## statechart_method 
        public int openTakeNull() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            open_exit();
            readyToClose_entDef();
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void open_entDef() {
            open_enter();
        }
        
        //## statechart_method 
        public void readyToClose_enter() {
            rootState_subState = readyToClose;
            rootState_active = readyToClose;
            readyToCloseEnter();
        }
        
        //## statechart_method 
        public void openEnter() {
        }
        
        //## statechart_method 
        public void readyToClose_entDef() {
            readyToClose_enter();
        }
        
        //## statechart_method 
        public int rootState_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void openExit() {
        }
        
        //## statechart_method 
        public void closedEnter() {
        }
        
        //## statechart_method 
        public void open_exit() {
            popNullConfig();
            openExit();
        }
        
        //## statechart_method 
        public void rootState_enter() {
            rootStateEnter();
        }
        
        //## statechart_method 
        public void rootStateEnter() {
        }
        
        //## statechart_method 
        public int closed_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(OpenDoors.OpenDoors_CargoLiftSystem_id))
                {
                    res = closedTakeOpenDoors();
                }
            
            return res;
        }
        
        //## statechart_method 
        public int readyToClose_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(RiJEvent.TIMEOUT_EVENT_ID))
                {
                    res = readyToCloseTakeRiJTimeout();
                }
            else if(event.isTypeOf(LeaveDoorsOpen.LeaveDoorsOpen_CargoLiftSystem_id))
                {
                    res = readyToCloseTakeLeaveDoorsOpen();
                }
            
            return res;
        }
        
        //## statechart_method 
        public int readyToCloseTakeLeaveDoorsOpen() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            readyToClose_exit();
            open_entDef();
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public void closed_exit() {
            closedExit();
        }
        
        //## statechart_method 
        public int readyToCloseTakeRiJTimeout() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.getTimeoutId() == Doors_Timeout_readyToClose_id)
                {
                    readyToClose_exit();
                    closed_entDef();
                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                }
            return res;
        }
        
        //## statechart_method 
        public void rootStateEntDef() {
            closed_entDef();
        }
        
        //## statechart_method 
        public void closed_enter() {
            rootState_subState = closed;
            rootState_active = closed;
            closedEnter();
        }
        
        //## statechart_method 
        public void rootStateExit() {
        }
        
        //## statechart_method 
        public void open_enter() {
            pushNullConfig();
            rootState_subState = open;
            rootState_active = open;
            openEnter();
        }
        
        //## statechart_method 
        public void readyToCloseExit() {
            itsRiJThread.unschedTimeout(Doors_Timeout_readyToClose_id, this);
        }
        
        //## statechart_method 
        public void readyToCloseEnter() {
            itsRiJThread.schedTimeout(3000, Doors_Timeout_readyToClose_id, this, null);
        }
        
    }
}
/*********************************************************************
	File Path	: DefaultComponent/DefaultConfig/CargoLiftSystem/Doors.java
*********************************************************************/

